package com.qk.ezbuy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qk.ezbuy.dao.ProductMapper;
import com.qk.ezbuy.pojo.Product;
import com.qk.ezbuy.pojo.User;
import com.qk.ezbuy.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    @Override
    public PageInfo<Product> selectPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Product> list = productMapper.selectAll();
        PageInfo<Product> pageInfo = new PageInfo<Product>(list,3);
        return pageInfo;
    }

    @Override
    public int updateByPrimaryKeySelective(Product record) {
        return productMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public List<Product> selectAll() {
        return productMapper.selectAll();
    }

    @Override
    public Product selectById(Integer id) {
        return productMapper.selectById(id);
    }

    @Override
    public PageInfo<Product> selectByParentId(Map<String, Object> map) {
        Integer pageNum = Integer.parseInt(map.get("pageNum").toString());
        Integer pageSize = Integer.parseInt(map.get("pageSize").toString());
        PageHelper.startPage(pageNum, pageSize);
        List<Product> list = productMapper.selectByParentId(map);
        PageInfo<Product> pageInfo = new PageInfo<Product>(list,3);
        System.out.println(pageInfo.getNavigatepageNums()[0]);
        return pageInfo;
    }
}